CODESYS OPC UA Client API
Product: CODESYS OPC UA Client API SL
Description
The example shows how to use the OPC Client API library. The sample project contains an OPC UA Server configuration and an OPC UA Client configuration. Server/Client communication takes place via localhost.
Additional information
Preparation
Connect to the controller. Use the following credentials:
Name:
user1Password:
user1The
user1must be a member of the Administrator group.
Important
You need to use these credentials for the example because the OPC UA Client signs in to the OPC UA Server with this data.
Add the certificates for OPC UA Server and OPC UA Client to the trusted certificates.

The certificate for UaExpert is required only if you want to connect to the OPC UA Server from an external UaExpert instance (for example, to get more server information).
Structure of the project
Server
Server: (GVL) Defines variables which are used for the symbol configuration of the OPC UA Server.PLC_PRG_Server: Writes variables toGVL Serverwith a cyclical counter.Symbol configuration: Defines the symbol configuration of the OPC UA Server. It contains all variables and symbols of the GVL server.OPC UA Server in the UaExpert program.

Client
Client: (GVL) Defines all variables which are published by the subscription. Updated when the subscription is active and the publication is released.UAVars: (GVL) Defines constants and variables which are used by the client to establish a connection to the OPC UA Server.NamespaceArray (FB): Translation table for node IDs which are used on the application side. The function block is prepared only for optional use and is not used in the standard setup of the sample project.PLC_PRG: Cyclical call of all function blocks used in the OPC UA Client API:Client,Subscription,Read, andWrite.ValueSet: Setup of values which are used by theReadand/orWritefunction blocks.Subscription: Defines a subscription which publishes all variables of the GVL client.
Testing the project in online mode
Tip
Use a watch list to run the sample project.
Set
PLC_PRG.xEnabletoTRUE.This allows the
Clientfunction block to establish a connection to the server.
The status of
CONNECTION_STATEchanges toCONNECTEDand theUAClient.xActiveoutput becomesTRUE. Now the activation of a subscription, read actions, and write actions is possible.Set
PLC_PRG.xSubscribetoTRUE.This allows the
Subscriptionfunction block to create a subscription on the server and publish all values in GVL client variables.
Make sure that
xPublishingEnabled=TRUEso thatSUBSCRIPTION_STATEbecomes active.Set
PLC_PRG.xReadtoTRUE.This enables a read action which is done by the
Readfunction block.
Switch
PLC_PRG.xReadso that a new read action is triggered.Set
PLC_PRG.xWritetoTRUE.This enables a write action by the
Writefunction block.
Switch
PLC_PRG.xReadso that a new read action is triggered.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.18.40 or higher) |
Runtime system | CODESYS Control Win (version 3.5.18.40) |
Add-on components |
|
Note
DOWNLOAD Project